package com.xgimi.open.skill.datamanager.biz.common.redis;

import com.xgimi.redis.RedisDAO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName Context
 * @Descrition TODO
 * @Author xiaoxiong.sun
 * @Date 2022/11/09 18:55
 **/
@Component
public class RedisService {

    @Resource
    private RedisDAO redisDAO;


    public Long incr(String key) {
        return redisDAO.incr(key);
    }

    public String get(String key) {
        return redisDAO.getString(key);
    }

    /**
     * unit is second
     */
    public void setEx(String key, String value, int timeout) {
        redisDAO.setString(key, value, timeout);
    }

    public void set(String key, String value) {
        redisDAO.setString(key, value);
    }

    public Long expire(String key, Integer timeout) {
        return redisDAO.expire(key, timeout);
    }

    public Long del(String key) {
        return redisDAO.del(key);
    }

    public Boolean exists(String key) {
        return redisDAO.exists(key);
    }

    public boolean setnx(String key, String value) {

        Long l = redisDAO.setnx(key, value);
        Long fl = 0L;
        if (l.equals(fl)) {
            return false;
        }

        return true;
    }

}
